#include<iostream>
using namespace std;
#include<vector>

int maxSubArray(vector<int>& nums) {
	int length1 = nums.size();
	vector<int>dp(length1, 0);
	dp[0] = nums[0];
	int maxNumber = dp[0];
	
	for (int i = 1; i < length1; i++)
	{
		dp[i] = max(dp[i - 1] + nums[i], nums[i]);
		maxNumber = max(maxNumber, dp[i]);
	}
	return maxNumber;
}

int main()
{
	vector<int> nums = { -2,1,-3,4,-1,2,1,-5,4 };
	maxSubArray(nums);
	return 0;
}